package com.eshop.product.mapper;

import com.eshop.product.model.Product;
import org.apache.ibatis.annotations.*;

/**
 * @ClassName CategoryMapper
 * @Description
 * @Author 47980
 * @Date 2020/5/17 16:08
 * @Version V_1.0
 **/
@Mapper
public interface ProductMapper {

    @Insert("INSERT INTO product(name,brand_id,category_id) VALUES(#{name},#{brandId},#{categoryId})")
    public void add(Product product);

    @Update("UPDATE product SET name=#{name},brand_id=#{brandId},category_id=#{categoryId} WHERE id=#{id}")
    public void update(Product product);

    @Delete("DELETE FROM product WHERE id=#{id}")
    public void delete(Long id);

    @Select("SELECT * FROM product where id=#{id}")
    @Results({
        @Result(column = "category_id", property = "categoryId"),
        @Result(column = "brand_id", property = "brandId")
    })
    public Product findById(Long id);
}
